package com.example.waterdispenserm2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.waterdispenserm2.R;
import com.example.waterdispenserm2.bean.M2UIItem;

import java.util.List;

/**
 * 错误信息列表适配器
 */
public class M2HomeAdapter extends BaseAdapter {


    private List<M2UIItem> list;
    private Context context;



    public M2HomeAdapter(List<M2UIItem> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.m2_item, parent, false);
        }
        RelativeLayout linearLayout = convertView.findViewById(R.id.ll_item);
        TextView name = convertView.findViewById(R.id.tv_name);
        TextView taste = convertView.findViewById(R.id.tv_taste);

        name.setText(list.get(position).getName());
        taste.setText(list.get(position).getTaste());

        if (list.get(position).isSelect()) {
            linearLayout.setBackgroundResource(R.drawable.bg_m2_item_true);
        } else {
            linearLayout.setBackgroundResource(R.drawable.bg_m2_item);
        }



        return convertView;
    }


}